<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>数据类型</title>
    <script>
      /* 
        JavaScript 是一种弱类型或者说动态语言
        在代码运行时，变量的数据类型是由 JS引擎 根据 = 右边变量值的数据类型来判断 的，运行完毕之后，变量就确定了数据类型。
        JavaScript 拥有动态类型，同时也意味着相同的变量可用作不同的类型

        数据类型分类:
        简单数据类型（Number,String,Boolean,Undefined,Null,...）
        复杂数据类型（Object)
      */
      let num = 3 //数字类型number
      let name = '张三' //字符串类型string
      let isNum = true //布尔类型boolean
      // 获取指定变量的数据类型
      console.log(typeof num)
      console.log(typeof name)
      console.log(typeof isNum)

      /* 
        数字类型number
        整数或者浮点数,可以直接运算

        注意: 数字类型具有它的范围,如果数据超过范围,则得到 ±Infinity,表示无穷无尽
      */
      let n1 =
        -100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
      let n2 = -9.8
      console.log(n1)
      console.log(n2 + 1)
      console.log(typeof n1, typeof n2)

      //获取数字类型的极值范围 5e-324 1.7976931348623157e+308
      console.log(Number.MIN_VALUE, Number.MAX_VALUE)

      //判断变量是否不是数字
      //注意: NaN = no a number
      console.log(isNaN(n2)) //false

      /* 
        字符串类型
        注意: 
        JS中字符串可以使用双引号或者单引号修饰,更推荐使用单引号
        嵌套时, 必须使用外双内单，外单内双
      */
      let email = 'abc123@qq.com'
      let orderno = '20231020094630'
      console.log(orderno + 1) //202310200946301,字符串+号是拼接,而非数学运算
      console.log(orderno - 1) //20231020094629,减法-是可以正常运算的

      console.log('我是"Java"程序员')
      console.log("我是'Java'程序员")

      //字符串转义,在需要被转换的符号前添加\
      //\n表示换行
      console.log('我的篮球游戏在D:\\nba目录.')

      //\t表示tab间隔
      console.log('我的临时目录是C:\\temp目录.')

      //console.log('我是\'Java\'程序员')

      //关于字符串拼接问题
      console.log(1 + 1) //数学和
      console.log('1' + 1)
      console.log(1 + '1')
      console.log('1' + '1')
      console.log('1' - 1) //减法可以成功
      console.log('abc' + 1) //abc1
      console.log('abc' - 1) // NaN

      //获取字符串的长度(字符数)
      let myName = 'Sherlock'
      console.log(myName.length) //8

      /* 
        布尔类型 boolean
        true和false,对应1和0,用来判断真假
      */
      console.log(true)
      //console.log(true + 1)
    </script>
  </head>
  <body></body>
</html>
